const https = require('https');
const http = require('http');
var qs = require('querystring');
var cookieList = [];
//账号列表
var userLogin = ["1418154909", "2893303772", "2700356786"];
function ajax(data, cookie) {
    return new Promise((resolve, reject) => {
        var post_data = { ...data };
        // var content = qs.stringify(post_data);
        var content = JSON.stringify(post_data);
        console.log(cookie);
        var options = {
            hostname: 'localhost',
            port: 3000,
            path: '/test',
            method: 'POST',
            headers: {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36",
                "Referer": "https://adnet.qq.com/report/list",
                "Origin": "https://adnet.qq.com",
                "Host": "adnet.qq.com",
                "Content-Type": "application/json",
                "cookie": cookie
            }
        };
        var req = http.request(options, function (res) {
            console.log('STATUS(响应状态): ' + res.statusCode);
            console.log('HEADERS(响应头): ' + JSON.stringify(res.headers));
            res.setEncoding('utf8');
            res.on('data', function (chunk) {
                console.log('BODY(响应体): ' + chunk);
                resolve(chunk);
            });
        });
        
        req.on('error', function (e) {
            console.log('problem with request(请求失败): ' + e.message);
            reject(e);
        });
        // 将数据写入请求体
        req.write(content);//注意这个地方  
        req.end();
    })

}

ajax({
    "newPlacementAddVo": {
        "memberId": 605080606512,
        "mediumId": 40305412446397,
        "placementName": "测试广告位1",
        "adPullMode": "SDK",
        "osType": "Android",
        "scene": "Flash",
        "subScene": "LoginReward",
        "subSceneDescription": null,
        "placementImageUrl": "/img/placementScene/68364ee1b648434c8e2865fa16bf8c46.png",
        "renderType": "Normal",
        "informationPlacementType": "Normal",
        "adCrtTypeList": ["IMAGE"],
        "adCrtSizeId": 2,
        "adCrtTemplateId": null,
        "nativePlacement": {
            "linkHasIcon": true,
            "linkHasImage": true,
            "linkHasTitle": true,
            "linkHasDesc": true,
            "appHasIcon": true,
            "appHasImage": true,
            "appHasName": true,
            "appHasDesc": true,
            "appHasRating": true,
            "appHasPrice": true,
            "appHasDownloadCount": true
        },
        "bidSettingStrategy": 0,
        "filterRule": {
            "filterCategoryIds": []
        },
        "informationPlacementPosition": ["EndText", "ReadText", "TopBanner"],
        "normalRenderVersion": 1,
        "enableExperiment": false,
        "adCrtTemplateIds": [],
        "templateVersion": 1
    }
}, "token=31e4defe-f2b5-4f8b-ab74-78f166532afc; userName=guodong");
